/**
 * 
 * @author libai
 *
 *you can find a num from a Circular array
 */
public class CircularArrayFinder implements Finder {
	
	public int find(int[] data, int k){
		/**
		 * the place or the inserted place of the num be printed and returned
		 */
		int l1=data.length;
		int k1;
		if(k>=data[0])
		{
			for(int i=0;i<l1;i++)
			{
				if(k==data[i])
				{
					System.out.println("the place is:"+i);
					return i;
				}
				if(k<data[i])
				{
					System.out.println("the inserted place is:"+i);
					return i;
				}
				if(i==l1-1)
				{
					System.out.println("the inserted place is:"+(i+1));
					return i+1;
				}
				if(data[i+1]<data[i])
				{
					System.out.println("the inserted place is:"+(i+1));
					return i+1;
				}
				
			}
		}
		else
		{
			for(int i=l1-1;i>0;i--)
			{
				if(k==data[i])
				{
					
					for(k1=i;(k==data[k1])&&(k1>=0);k1--)
					{}
					System.out.println("the place is:"+(k1+1));
					return k1+1;
				}
				if(data[i-1]>data[i])
				{
					System.out.println("the inserted place is:"+i);
					return i;
				}
				if(k>data[i])
				{
					System.out.println("the inserted place is:"+(i+1));
					return i+1;
				}
				
			}
	}
		System.out.println("the inserted place is:"+0);
		return 0;
}
	}
	